package com.test.springsecurity.controller;

import com.test.springsecurity.entity.AppUser;
import com.test.springsecurity.service.UserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;
    @PreAuthorize("hasAuthority('user:find')")
    @GetMapping("/find")
    public String find(){
        return "find";
    }
    @PreAuthorize("hasAuthority('user:del')")
    @GetMapping("/del")
    public String del(){
        return "del";
    }

    @GetMapping("/regist")
    public String regist(AppUser user){
        //调用service注册方法 在方法中对密码进行加密
        userService.add(user);

        return "success";

    }
}
